package com.yxx.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yxx.annotation.OptLogger;
import com.yxx.annotation.VisitLogger;
import com.yxx.entityModel.vo.Result.PageResult;
import com.yxx.entityModel.vo.Result.ResponseResult;
import com.yxx.entityModel.vo.query.AlbumQuery;
import com.yxx.entityModel.vo.request.AlbumRequest;
import com.yxx.entityModel.vo.response.AlbumBackResponse;
import com.yxx.entityModel.vo.response.AlbumResponse;
import com.yxx.service.AlbumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

import static com.yxx.constant.OptTypeConstant.*;

/**
 * 相册控制器
 * @author yuxiangxun
 * @date 2025/2/11
 * @apiNote
 */
@Api(tags = "相册模块")
@RestController
public class AlbumController {

    @Resource
    private AlbumService albumService;

    /**
     * 查看后台相册列表
     *
     * @param albumQuery 相册查询条件
     * @return {@link PageResult< AlbumBackResponse >} 后台相册列表
     */
    @ApiOperation(value = "查看后台相册列表")
    @SaCheckPermission("web:album:list")
    @GetMapping("/admin/album/list")
    public ResponseResult<PageResult<AlbumBackResponse>> listAlbumBackVO(AlbumQuery albumQuery) {
        return ResponseResult.success(albumService.listAlbumBackVO(albumQuery));
    }

    /**
     * 上传相册封面
     * @param file
     * @return
     */
    @OptLogger(value = UPLOAD)
    @ApiOperation(value = "上传相册封面")
    @ApiModelProperty(value = "相册封面",name = "file", required = true, dataType = "MultipartFile")
    @SaCheckPermission("web:album:upload")
    @PostMapping("/admin/album/upload")
    public ResponseResult<String> uploadAlbumCover(@RequestParam("file") MultipartFile file){
        return ResponseResult.success(albumService.uploadAlbumCover(file));
    }


    /**
     * 添加相册
     *
     * @param albumRequest 相册信息
     * @return {@link ResponseResult<>}
     */
    @OptLogger(value = ADD)
    @ApiOperation(value = "添加相册")
    @SaCheckPermission("web:album:add")
    @PostMapping("/admin/album/add")
    public ResponseResult<?> addAlbum(@Validated @RequestBody AlbumRequest albumRequest) {
        albumService.addAlbum(albumRequest);
        return ResponseResult.success();
    }
    /**
     * 删除相册
     * @param albumId 相册id
     * @return {@link ResponseResult}
     */
    @OptLogger(value = DELETE)
    @ApiOperation(value = "删除相册")
    @SaCheckPermission("web:album:delete")
    @DeleteMapping("/admin/album/delete/{albumId}")
    public ResponseResult<?> deleteAlbum(@PathVariable("albumId") Integer albumId) {
        albumService.deleteAlbum(albumId);
        return ResponseResult.success();
    }

    /**
     * 修改相册
     *
     * @param albumRequest 相册信息
     * @return {@link ResponseResult<>}
     */
    @OptLogger(value = UPDATE)
    @ApiOperation(value = "修改相册")
    @SaCheckPermission("web:album:update")
    @PutMapping("/admin/album/update")
    public ResponseResult<?> updateAlbum(@Validated @RequestBody AlbumRequest albumRequest) {
        albumService.updateAlbum(albumRequest);
        return ResponseResult.success();
    }

    /**
     * 编辑相册
     * @param albumId 相册id
     * @return {@link ResponseResult< AlbumRequest >} 相册
     */
    @ApiOperation(value = "编辑相册")
    @SaCheckPermission("web:album:edit")
    @GetMapping("/admin/album/edit/{albumId}")
    public ResponseResult<AlbumRequest> editAlbum(@PathVariable("albumId") Integer albumId) {
        return ResponseResult.success(albumService.editAlbum(albumId));
    }

    /**
     * 查看相册列表
     * @return {@link ResponseResult< AlbumResponse > 相册列表
     */
    @VisitLogger(value = "相册")
    @ApiOperation(value = "查看相册列表")
    @GetMapping("/album/list")
    public ResponseResult<List<AlbumResponse>> listAlbumVO() {
        return ResponseResult.success(albumService.listAlbumVO());
    }


}
